package com.dearbinge.utils.sms.demo;


import java.io.UnsupportedEncodingException;

import com.alibaba.fastjson.JSON;
import com.dearbinge.utils.sms.sms.request.SmsSendRequest;
import com.dearbinge.utils.sms.sms.response.SmsSendResponse;
import com.dearbinge.utils.sms.sms.util.ChuangLanSmsUtil;
/**
 *
 * @author tianyh
 * @Description:普通短信发送
 */
public class SmsSendDemo {

	public static final String charset = "utf-8";
	// 请登录zz.253.com 获取创蓝API账号(非登录账号,示例:N1234567)
	public static String account = "N8456317";
	// 请登录zz.253.com 获取创蓝API密码(非登录密码)
	public static String pswd = "e8Mcv4upH";
	//短信发送的URL 请登录zz.253.com 获取完整的URL接口信息
	public static String smsSingleRequestServerUrl = "http://smssh1.253.com/msg/send/json";
	//状态报告
	public static String report= "true";


	public static void main222(String[] args) throws UnsupportedEncodingException {

		//短信发送的URL 请登录zz.253.com 获取完整的URL接口信息
		String smsSingleRequestServerUrl = "http://smssh1.253.com/msg/send/json";

		// 设置您要发送的内容：其中“【】”中括号为运营商签名符号，多签名内容前置添加提交
	    String msg = "【253云通讯】你好,你的验证码是123456";
		//手机号码
		String phone = "18575311501";
		//状态报告
		String report= "true";

		SmsSendRequest smsSingleRequest = new SmsSendRequest(account, pswd, msg, phone,report);

		String requestJson = JSON.toJSONString(smsSingleRequest);

		System.out.println("before request string is: " + requestJson);

		String response = ChuangLanSmsUtil.sendSmsByPost(smsSingleRequestServerUrl, requestJson);

		System.out.println("response after request result is :" + response);

		SmsSendResponse smsSingleResponse = JSON.parseObject(response, SmsSendResponse.class);

		System.out.println("response  toString is :" + smsSingleResponse);
	}

	/**
	 *
	 * @param msg  验证码
	 * @param phone 手机号
	 * @return true成功 false 失败
	 */
	public static String sendSms(String msg ,String phone){
		SmsSendRequest smsSingleRequest = new SmsSendRequest(account, pswd, "账号手机绑定【短信验证码:】15分钟内输入有效(请勿向任何人泄露)"+msg, phone,report);
		String requestJson = JSON.toJSONString(smsSingleRequest);
		String response = ChuangLanSmsUtil.sendSmsByPost(smsSingleRequestServerUrl, requestJson);
		SmsSendResponse smsSingleResponse = JSON.parseObject(response, SmsSendResponse.class);
		System.out.println("response  toString is :" + smsSingleResponse.getCode());
		if("0".equals(smsSingleResponse.getCode())){
			return "true";
		}else{
			return "false";
		}
	}
//
//	public static void main(String[] args) throws UnsupportedEncodingException {
//		boolean sendSms = sendSms("123456","18575311501");
//		System.out.println(sendSms);
//	}


}
